What is stackframe?
The stackframe npm package is a library that allows for manipulation and introspection of stack frames. It provides a simple way to work with stack traces, allowing users to parse and manipulate call stacks programmatically.
What are stackframe's main functionalities?
Creating StackFrame objects
This feature allows users to create StackFrame objects that represent a call stack's frame. The object can include details such as the function name, arguments, file name, line number, and column number.
var StackFrame = require('stackframe');
var frame = new StackFrame({functionName: 'funName', args: ['args'], fileName: 'file.js', lineNumber: 1, columnNumber: 3288});
Getting and setting properties
This feature allows users to get and set properties of a StackFrame object, such as the function name, file name, line number, etc. This can be useful for modifying or inspecting a frame's details.
var StackFrame = require('stackframe');
var frame = new StackFrame();
frame.setFunctionName('funName');
var functionName = frame.getFunctionName();
Stringifying StackFrame objects
This feature allows users to convert a StackFrame object into a string representation, which can be useful for logging or displaying the stack frame in a readable format.
var StackFrame = require('stackframe');
var frame = new StackFrame({functionName: 'funName', fileName: 'file.js', lineNumber: 1, columnNumber: 3288});
var stringifiedFrame = frame.toString();
Other packages similar to stackframe
error-stack-parser
This package is similar to stackframe in that it provides functionality for parsing JavaScript Error stacks. It extracts stack frames from the Error object and returns them as an array of StackFrame-like objects. It differs in that it focuses more on parsing existing Error stacks rather than creating and manipulating StackFrame objects.
stack-trace
This package is used to get v8 stack traces at any arbitrary point in time. It provides more detailed information about the stack trace and is often used for debugging purposes. Unlike stackframe, it is more focused on capturing and analyzing the current call stack rather than creating and manipulating StackFrame objects.
stackframe
JS Object representation of a stack frame
Underlies functionality of other modules within stacktrace.js.
Written to closely resemble StackFrame representations in Gecko and V8
Usage
var stackFrame = new StackFrame({
functionName: 'funName',
args: ['args'],
fileName: 'http://localhost:3000/file.js',
lineNumber: 1,
columnNumber: 3288,
isEval: true,
isNative: false,
source: 'ORIGINAL_STACK_LINE'
evalOrigin: new StackFrame({functionName: 'withinEval', lineNumber: 2, columnNumber: 43})
});
stackFrame.functionName
stackFrame.setFunctionName('newName')
stackFrame.getFunctionName()
stackFrame.args
stackFrame.setArgs([])
stackFrame.getArgs()
stackFrame.fileName
stackFrame.setFileName('http://localhost:3000/file.js')
stackFrame.getFileName()
stackFrame.lineNumber
stackFrame.setLineNumber(325)
stackFrame.getLineNumber()
stackFrame.columnNumber
stackFrame.setColumnNumber(20)
stackFrame.getColumnNumber()
stackFrame.source
stackFrame.setSource('NEW_SOURCE')
stackFrame.getSource()
stackFrame.isEval
stackFrame.setIsEval(false)
stackFrame.getIsEval()
stackFrame.isNative
stackFrame.setIsNative(true)
stackFrame.getIsNative()
stackFrame.evalOrigin
stackFrame.setEvalOrigin({functionName: 'evalFn', fileName: 'anonymous'})
stackFrame.getEvalOrigin().getFunctionName()
stackFrame.toString()
Browser Support
Installation
npm install stackframe
bower install stackframe
https://raw.githubusercontent.com/stacktracejs/stackframe/master/dist/stackframe.min.js